#!/bin/sh

# This is a short, non-critical script to issue the commands
# for rebuilding the configure script.

topdir="`echo $0 | sed -e 's:^[^/]\{1,\}$:./\&:' -e 's:/[^/]\{1,\}$::'`/../.."

set -x

# Go to the top-level directory.
cd "$topdir"

# We don't always have to remove the cache, but I'm not sure when we
# should so just remove it.
rm -rf autom4te.cache

# This generates the aclocal.m4 file.
# aclocal grabs needed macros and put them in aclocal.m4.
# Having aclocal.m4 allows one to regenerate configure after
# a "minor change" without having to look for macros.
# A minor change is one that does not require a new macro.
aclocal"$AUTOMAKE_VERSION" -I `pwd`/config --output=config/aclocal.m4

# This generates config/SAMRAI_config.h.in
# The file is generated based on the AH_TOP and AH_BOTTOM macros
# and the numerous use of AC_DEFINE.
#
# We remove some macros because they conflict with other packages
# using autoconf, and we don't use these macros anyway.
autoheader"$AUTOCONF_VERSION" -I config
sed -i -e 's/^\(#undef \(PACKAGE\|VERSION\)\)/\/\/ Removed due to name conflict \1/' config/SAMRAI_config.h.in
sed -i -e 's/\(F77_FUNC\)/SAMRAI_\1/' config/SAMRAI_config.h.in

# This generates configure
autoconf"$AUTOCONF_VERSION" -I config || exit 1
